package com.app.repository.impl;

import com.app.model.main.CommentsOfComments;
import com.app.repository.interfaces.CommentsOfCommentsMapper;
import com.app.support.dao.MybatisDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lichaojie on 2017/3/12. It's a beautiful day.
 */
@Repository
public class CommentsOfCommentsMapperImpl implements CommentsOfCommentsMapper {

    @Autowired
    private MybatisDao mybatisDao;

    @Override
    public int deleteByPrimaryKey(Long id){
        return mybatisDao.delete("com.app.dao.main.CommentsOfCommentsMapper", ".deleteByPrimaryKey", id);
    }

    @Override
    public int insert(CommentsOfComments record){
        return mybatisDao.insert("com.app.dao.main.CommentsOfCommentsMapper", ".insert", record);
    }

    @Override
    public int insertSelective(CommentsOfComments record){
        return mybatisDao.insert("com.app.dao.main.CommentsOfCommentsMapper", ".insertSelective", record);
    }

    @Override
    public CommentsOfComments selectByPrimaryKey(Long id){
        return mybatisDao.get("com.app.dao.main.CommentsOfCommentsMapper", ".selectByPrimaryKey", id);
    }

    @Override
    public CommentsOfComments selectByParam(long userId, String time){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("time",time);
        return mybatisDao.get("com.app.dao.main.CommentsOfCommentsMapper",".selectByParam",map);
    }

    @Override
    public int updateByPrimaryKeySelective(CommentsOfComments record){
        return mybatisDao.update("com.app.dao.main.CommentsOfCommentsMapper", ".updateByPrimaryKeysSelective", record);
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(CommentsOfComments record){
        return mybatisDao.update("com.app.dao.main.CommentsOfCommentsMapper",".updateByPrimaryKeyWithBLOBs",record);
    }

    @Override
    public int updateByPrimaryKey(CommentsOfComments record){
        return mybatisDao.update("com.app.dao.main.CommentsOfCommentsMapper",".updateByPrimaryKey",record);
    }

    @Override
    public List<CommentsOfComments> getListOrderedByIdDESC(long commentsv1Id, long lastId, int page, int number){
        Map<String,Object> map = new HashMap<>();
        map.put("commentsv1Id",commentsv1Id);
        map.put("lastId",lastId);
        return mybatisDao.getList("com.app.dao.main.CommentsOfCommentsMapper", ".getListOrderedByIdDESC", map, new RowBounds(0, number));
    }

    @Override
    public List<CommentsOfComments> getListOrderedByIdASC(long commentsv1Id, long lastId, int page, int number){
        Map<String,Object> map = new HashMap<>();
        map.put("commentsv1Id",commentsv1Id);
        map.put("lastId",lastId);
        return mybatisDao.getList("com.app.dao.main.CommentsOfCommentsMapper",".getListOrderedByIdASC",map,new RowBounds(0,number));
    }

    @Override
    public long getCommentsv2Number(long commentsv1Id){
        return mybatisDao.count("com.app.dao.main.CommentsOfCommentsMapper",".getCommentsv2Number",commentsv1Id);
    }

    @Override
    public long getMaxId(){
        return mybatisDao.count("com.app.dao.main.CommentsOfCommentsMapper",".getMaxId",null);
    }

    @Override
    public List<CommentsOfComments> getListByUserId(long userId){
        return mybatisDao.getList("com.app.dao.main.CommentsOfCommentsMapper",".getListByUserId",userId);
    }
}
